package com.mdd.admin.controller.specification;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.specification.IGoodsSpecificationService;
import com.mdd.admin.validate.specification.GoodsSpecificationParam;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.vo.specification.GoodsSpecificationListVo;
import com.mdd.admin.vo.specification.GoodsSpecificationDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 服务规格管理
 */
@RestController
@RequestMapping("api/specification")
public class GoodsSpecificationController {

    @Resource
    IGoodsSpecificationService iGoodsSpecificationService;

    /**
     * 服务规格列表
     *
     * @param pageParam 分页参数
     * @param params 搜索参数
     * @return Object
     */
    @GetMapping("/list")
    public Object list(@Validated PageParam pageParam,
                       @RequestParam Map<String, String> params) {
        PageResult<GoodsSpecificationListVo> list = iGoodsSpecificationService.list(pageParam, params);
        return AjaxResult.success(list);
    }
    /**
     * 服务规格详情
     *
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        GoodsSpecificationDetailVo detail = iGoodsSpecificationService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 服务规格新增
     *
     * @param goodsSpecificationParam 参数
     * @return Object
     */
    @Log(title = "服务规格新增")
    @PostMapping("/add")
    public Object add(@Validated(value = GoodsSpecificationParam.create.class) @RequestBody GoodsSpecificationParam goodsSpecificationParam) {
        iGoodsSpecificationService.add(goodsSpecificationParam);
        return AjaxResult.success();
    }

    /**
     * 服务规格编辑
     *
     * @param goodsSpecificationParam 参数
     * @return Object
     */
    @Log(title = "服务规格编辑")
    @PostMapping("/edit")
    public Object edit(@Validated(value = GoodsSpecificationParam.update.class) @RequestBody GoodsSpecificationParam goodsSpecificationParam) {
        iGoodsSpecificationService.edit(goodsSpecificationParam);
        return AjaxResult.success();
    }

    /**
     * 服务规格删除
     *
     * @param goodsSpecificationParam 参数
     * @return Object
     */
    @Log(title = "服务规格删除")
    @PostMapping("/del")
    public Object del(@Validated(value = GoodsSpecificationParam.delete.class) @RequestBody GoodsSpecificationParam goodsSpecificationParam) {
        iGoodsSpecificationService.del(goodsSpecificationParam.getId());
        return AjaxResult.success();
    }

}
